package ru.housewife.form;

/**
 * Form object for
 * @see ru.housewife.model.WareRegionPrice
 *
 * @author Alexander Troshanin
 */
public class WareRegionPriceForm {

    private WareForm ware;

    private RegionForm region;

    private double price;

    private Key key;

    public WareRegionPriceForm(WareForm ware, RegionForm region, double price) {
        this.ware = ware;
        this.region = region;
        this.price = price;
        key = new Key(ware.getId(), region.getId());
    }

    public WareForm getWare() {
        return ware;
    }

    public RegionForm getRegion() {
        return region;
    }

    public double getPrice() {
        return price;
    }

    public Key getKey() {
        return key;
    }

    public static class Key {
        long wareId;
        long regionId;

        public Key(long wareId, long regionId) {
            this.wareId = wareId;
            this.regionId = regionId;
        }

        public long getWareId() {
            return wareId;
        }

        public long getRegionId() {
            return regionId;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o == null || getClass() != o.getClass()) {
                return false;
            }
            Key key = (Key) o;
            return regionId == key.regionId && wareId == key.wareId;

        }

        @Override
        public int hashCode() {
            int result = (int) (wareId ^ (wareId >>> 32));
            result = 31 * result + (int) (regionId ^ (regionId >>> 32));
            return result;
        }
    }
}
